<?php 
$req_path="./";
include_once($req_path."include/ini.php");
include($req_path."include/function.php");

define(_SERVER, $_SERVER);
define(_PORT, $_PORT);
define(_URI, $_URI);


class SMS
{	
	var $msisdn="";
	var $message="";
	var $sender="";
	function SMS($teleNo="",  $msg="", $sender=""){
		$this->msisdn=$teleNo;
		$this->message=$msg;
		$this->sender=$sender;
	}

	function SendSMS(){
		global $SMSusername, $SMSpassword , $_SERVER, $_PORT, $_URI ,$SMSsender;
		$ScheduledDelivery = '';
		
		$data_string = "username=" . urlencode($SMSusername) . 
						"&password=" . urlencode($SMSpassword) . 
						"&msisdn=" . urlencode($this->msisdn) . 
						"&message=" . urlencode($this->message) . 
						"&sender=" . urlencode($SMSsender) . 
						"&ScheduledDelivery=" . urlencode($ScheduledDelivery);
						
		$result = httpPost( _SERVER , _PORT , _URI, $data_string);
		
		if (!is_string($result)) {
			die("Fatal Error: Unable to connect to server.\n\n");
		} else {
			$xml = xml($result);
			$count = count($xml['SMS']['QUEUE']);
			if($count > 0){
				$count_pass = 0;
				$count_fail = 0;
				$used_credit = 0;
				for($i=0;$i<$count;$i++){
					if($xml['SMS']['QUEUE'][$i]['Status']){
						$count_pass++;
						$used_credit +=
						$xml['SMS']['QUEUE'][$i]['UsedCredit'];
					}else{
						$count_fail++;
					}
				}
				if($count_pass > 0){echo "Success: $count_pass messages, Total: $used_credit credits\n";}
				if($count_fail > 0){echo "Fail: $count_fail messages\n";}
			}else{
				echo ("Error: ".$xml['SMS']['Detail']."\n\n");
			}	 
		}		
	}
}

?>